<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <script src="js/jquery.min.js"></script>
    <script>
        function mysub(type) {
            var username = jQuery("#username");
            var password = jQuery("#password");
            var password2 = jQuery("#password2");
            if (type == 2) {
                if (confirm("是否确认清空？")) {
                    // 执行清空操作
                    username.val(""); // 清空
                    password.val("");
                    password2.val("");
                }
                return false;
            }
            if (username.val().trim() == "") {
                alert("请先输入用户名！");
                username.focus();
                return false;
            }
            if (password.val().trim() == "") {
                alert("请先输入密码！");
                password.focus();
                return false;
            }
            if (password2.val().trim() == "") {
                alert("请先输入确认密码！");
                password2.focus();
                return false;
            }
            // 判断密码和确认密码是否一致
            if(password.val()!=password2.val()){
                alert("两次输入的密码不一致，请重新输入密码！");
                password.focus();
                return false;
            }
            if(password.val().trim().length < 6) {
                alert("密码至少6位！")
                return false;
            }
            if(password.val().trim().length > 18) {
                alert("密码最多18位！")
                return false;
            }
            jQuery.getJSON("reg",{
                "username":username.val(),
                "password":password.val()
            },function (data) {
                if(data != null && data.state == 200) {
                    alert("注册成功");
                    location.href = "login.html"
                }else if(data != null && data.state == 400) {
                    alert("用户名重复！！")
                }else {
                    alert("抱歉，注册失败");
                }
            })
        }
    </script>

</head>
<body>
<div style="text-align: center;"  >
    <font face="宋体" size="5" color="red"><strong>---注册---</strong></font><p></p>
    <marquee direction="left" behavior="scroll"  scrollmount="1px" scolldely="4ms" width="250px" height="50px"><font face="宋体" color="#dc143c" size="4">❤终于等到你来了，赶快注册吧！结识更多的好友❤</font></marquee><br>
    &nbsp;&nbsp;&nbsp;&nbsp;用户名：<input id="username" name="username" type="text" style="background-color: bisque"><p></p>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;密&nbsp;&nbsp;码：<input id="password" name="password" type="password" style="background-color: bisque"><p></p>
    密码确认：<input id="password2" name="password2" type="password" style="background-color: bisque"><p></p>
    <input type="button" value="提交" onclick="mysub(1)" style="background-color: aquamarine">
    <input type="button" value="清空" onclick="mysub(2)" style="background-color: aquamarine"><p></p>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="login.html">已有账号,请登录...</a>
</div>
</body>
</html>